﻿using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Data.SqlClient;

using Jungle;
using Jungle.Code.Utils;
using Jungle.Code.Core;
using Jungle.Code.BLL;
using Jungle.Code.DAL;

public partial class DetailUser : System.Web.UI.UserControl
{
    public string PathUploads = "~/UserFiles/Images/Avatars/";
    public string err;

    public string NickName_err;
    public string Email_err;
 
    public int UserId;
    public string NickName;
    public string Name;
    public string Email;
    public int Country;
    public string City;
    public DateTime BirthDay;
    public string Password;
    public bool vip;
    public string ImageUrl;
    public DateTime RegDate;
    public string ICQ;
    public int RaitingZa;
    public int RaitingNet;
    public string Activation;
    public double Points;
    public string UserSignature;
    
    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
        fillDropDown1();
       base.OnInit(e);
    }
    
    //-------------------------------------------------------------------------------------
    public DataSet GetCountrys()
    {
        SqlConnection connect = new SqlConnection(DBHelper.ConnectionString);
        string s;
        DataSet ds1 = new DataSet();
        err = null;
        try
        {
            s = "select * from dbo.Countrys";

            ds1.Clear();
            SqlDataAdapter myData = new SqlDataAdapter(s, connect);
            myData.Fill(ds1);
        }
        catch (SqlException ex)
        {
            err = (ex.ToString());
        }
        finally
        {
            connect.Close();
        }
        return ds1;
    }
    //-------------------------------------------------------------------------------------
    private void fillDropDown1()
    {
        err = "";
        DataSet ds2 = new DataSet();
        ds2 = GetCountrys();
        Label20.Text = err;

        DropDownList1.Items.Clear();
        DropDownList1.DataSource = ds2.Tables[0].DefaultView;
        DropDownList1.DataTextField = "Name";        //(то, что видит юзер)
        DropDownList1.DataValueField = "ID";      //(value значения в <option>) 
        DropDownList1.DataBind();
        ListItem NewItemU = new ListItem();
        NewItemU.Text = "-- Выберите страну --";
        NewItemU.Value = "-1";
        NewItemU.Selected = true;
        DropDownList1.Items.Add(NewItemU);
    }
    //--------------------------------------------------------------
    public void HidePass()
    {
        Label6.Visible=false;
        TextBox6.Visible = false;
    }
    //--------------------------------------------------------------
    public void ShowPass()
    {
        Label6.Visible = true;
        TextBox6.Visible = true;
    }
    //--------------------------------------------------------------
    public void SetErr()
    {
        Label18.Text = NickName_err;
        Label19.Text = Email_err;
    }
    //--------------------------------------------------------------
    public void ClearErr()
    {
        Label18.Text = "";
        Label19.Text = "";
    }
    //--------------------------------------------------------------
    public void SetData()
    {
        TextBox12.Text = NickName;
        TextBox13.Text = Name;
        TextBox1.Text = Email;
        DropDownList1.SelectedValue = Convert.ToString (Country);
       
        TextBox4.Text = City;
        WebDateChooser1.Value =BirthDay;
        TextBox6.Text = ""; 
  
        if (ImageUrl.Trim() == "") Image1.Visible = false;

        if (ImageUrl.Trim() != "") Image1.Visible = true;
        if (File.Exists(Server.MapPath(ImageUrl)) == false) { Image1.Visible = false; }

        Image1.ImageUrl = ImageUrl;
        CheckBox1.Checked = vip;
        WebDateChooser2.Value =RegDate;

        TextBox8.Text = ICQ;
        TextBox9.Text = Convert.ToString(RaitingZa);
        TextBox10.Text = Convert.ToString(RaitingNet);
        if (Activation.Trim() == "true") CheckBox2.Checked = true; else CheckBox2.Checked = false;
        TextBox14.Text = Convert.ToString(Points);
        TextBox10.Text = UserSignature;
    }
    //--------------------------------------------------------------
    public void GetData()
    {
        NickName = TextBox12.Text;
        Name=TextBox13.Text;
        Email=TextBox1.Text ;
        Country = Convert.ToInt32(DropDownList1.SelectedItem.Value);
        City=TextBox4.Text;
        if (WebDateChooser1.Value != "")
            BirthDay = Convert.ToDateTime(WebDateChooser1.Value);
        Password= TextBox6.Text;
        ImageUrl=Image1.ImageUrl;
        vip=CheckBox1.Checked;
        if (WebDateChooser2.Value != "")
            RegDate = Convert.ToDateTime(WebDateChooser2.Value);
        ICQ=TextBox8.Text;
        //if (TextBox9.Text.Trim() == "") RaitingZa = 0; else RaitingZa = Convert.ToInt32(TextBox9.Text);
        //if (TextBox10.Text.Trim() == "") RaitingNet = 0; else RaitingNet = Convert.ToInt32(TextBox10.Text);

        if (CheckBox2.Checked == true) Activation = "true"; else Activation = "false";
        if (TextBox14.Text.Trim()=="") Points = 0; else Points=Convert.ToInt32(TextBox14.Text);
        UserSignature=TextBox10.Text;
    }
    //--------------------------------------------------------------
    public void ClearData()
    {
        ShowPass();
        fillDropDown1();
        DropDownList1.SelectedValue = "-1"; 

        TextBox12.Text="";
        TextBox13.Text="";
        TextBox1.Text="";
        TextBox4.Text="";
        WebDateChooser1.Value = "";
        TextBox6.Text="";
        Image1.Visible = false;
        Image1.ImageUrl="";
        CheckBox1.Checked=false;
        WebDateChooser2.Value = Convert.ToString(DateTime.Now);
        TextBox8.Text="";
        TextBox9.Text = "";
        TextBox10.Text="";
        CheckBox2.Checked =false;
        TextBox14.Text="0";
        TextBox10.Text="";
    }
    #endregion
       
   //-------------------------------------------------------------------------------------
    protected void DoUpload()
    {
        string CurrentPathBanners = Server.MapPath(PathUploads);
        string CurrentFileName;
        CurrentFileName = FileUpload1.FileName;

        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(CurrentPathBanners + CurrentFileName);
            //InfoText.Text = "Received " + FileUpload1.FileName + " Content Type " + FileUpload1.PostedFile.ContentType + " Length " + FileUpload1.PostedFile.ContentLength;
            ImageUrl = PathUploads + CurrentFileName;
             Image1.ImageUrl = ImageUrl;
             Image1.Visible = true;
             InfoText.Text = "";
            // Response.Write("Upload the file already  !!!");
        }
        else
        {
            InfoText.Text = "No uploaded file";
            Image1.Visible = false;
           // Response.Write("Can not load the file !");
        }
    }
    //-------------------------------------------------------------------------------------
    protected void Button1_Click(object sender, EventArgs e)
    {
        DoUpload();
    }
    //-------------------------------------------------------------------------------------
   protected void Page_Load(object sender, EventArgs e)
   {
      
   }
     
    
 }

